package com.andong.controller;

import com.andong.annotations.AccessControl;
import com.andong.domain.entity.Notification;
import com.andong.domain.pojo.PageResult;
import com.andong.domain.pojo.Result;
import com.andong.service.NotificationService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.time.LocalDate;
import java.util.List;

import static com.andong.utils.SystemConstant.*;

/**
 * (Notification)表控制层
 *
 * @author makejava
 * @since 2024-02-22 18:39:16
 */
@RestController
@RequestMapping("/notification")
public class NotificationController {
    /**
     * 服务对象
     */
    @Resource
    private NotificationService notificationService;

    @GetMapping("/list")
    public Result queryList(@RequestParam(defaultValue = "1") Integer page,
                            @RequestParam(defaultValue = "10") Integer pageSize,
                            String name,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        PageResult pageResult = notificationService.queryList(page, pageSize, name, begin, end);
        return Result.success(pageResult);
    }
    @PostMapping("/add")
    @AccessControl(roles = {ADMIN, SUPER_ADMIN}, permission = "通知管理")
    public Result saveOrModify(@RequestBody Notification notification) {
        return notificationService.saveOrModify(notification);
    }

    @DeleteMapping("/{ids}")
    @AccessControl(roles = {ADMIN, SUPER_ADMIN}, permission = "通知管理")
    public Result deleteByIds(@PathVariable List<Long> ids) {
        return notificationService.deleteByIds(ids);
    }

    @GetMapping("/{id}")
    @AccessControl(roles = {STUDENT, ADMIN, SUPER_ADMIN}, permission = "通知管理")
    public Result getById(@PathVariable Long id) {
        Notification notification = notificationService.getById(id);
        return Result.success(notification);
    }
}

